package biz.datalk.industrialland.admin.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.pagehelper.PageInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author tarofang@163.com
 * @date 2019年08月10日
 */
@Slf4j
@Configuration
@MapperScan(value = {"biz.datalk.**.mapper*"})
public class MybatisConfig {

    /**
     * 分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        log.debug("into");
        try {
            MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
            interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
            return interceptor;
        } finally {
            log.debug("out");
        }
    }///~

    @Bean
    public PageInterceptor paginationInterceptor() {
        log.debug("into");
        try {
            PageInterceptor pageInterceptor = new PageInterceptor();
            Properties properties = new Properties();
            properties.put("helperDialect", "mysql");
            properties.put("offsetAsPageNum", false);
            properties.put("rowBoundsWithCount", false);
            properties.put("pageSizeZero", false);
            properties.put("reasonable", false);
            properties.put("supportMethodsArguments", false);
            properties.put("autoRuntimeDialect", false);
            pageInterceptor.setProperties(properties);
            return pageInterceptor;
        } finally {
            log.debug("out");
        }
    }///~

}
